#!/bin/sh

. /usr/share/acpi-support/power-funcs

OUTPUT=LVDS
WACOM_DEVICE=stylus

do_rotate() {
	for x in /tmp/.X11-unix/*; do
		displaynum=`echo $x | sed s#/tmp/.X11-unix/X##`
		getXuser;
		if [ x"$XAUTHORITY" != x"" ]; then
			export DISPLAY=":$displaynum"
			if /usr/bin/xrandr --output $1 --rotate $2; then
				/usr/bin/xsetwacom set $3 rotate $4
			fi
		fi
	done
}

case "$1" in
	x_low)
	# right edge low, left edge high
	do_rotate $OUTPUT left $WACOM_DEVICE CCW
	;;
	x_high)
	# right edge high, left edge low
	do_rotate $OUTPUT right $WACOM_DEVICE CW
	;;
	y_low|normal)
	# front edge high, back edge low
	do_rotate $OUTPUT normal $WACOM_DEVICE NONE
	;;
	y_high)
	# front edge high, back edge low
	do_rotate $OUTPUT inverted $WACOM_DEVICE HALF
	;;
esac

